package com.javafive;

import java.io.*;

public class Demo13 {

    public static void main(String[] args)  throws  Exception {
        String file1="E:\\webWork\\javaKh62Demo\\src\\com\\javafive\\txt\\pet.template";
        String file2="E:\\webWork\\javaKh62Demo\\src\\com\\javafive\\txt\\pet.txt";
        replaceFile(file1,file2);
    }

    public static void replaceFile(String file1,String file2) throws  Exception {
        FileInputStream fis=new FileInputStream(file1);
        InputStreamReader isr=new InputStreamReader(fis,"utf-8");
        FileWriter fw = new FileWriter(file2);
        //创建 输入、输入出流对象.
        BufferedReader reader = new BufferedReader(isr);
        BufferedWriter writer = new BufferedWriter(fw);
        StringBuilder stringBuilder = new StringBuilder();
        String str=null;
        while ((str=reader.readLine())!=null){
            stringBuilder.append(str);
        }
        String strReader=stringBuilder.toString();
        strReader=strReader.replace("{name}","欧欧");
        strReader=strReader.replace("{type}","狗");
        strReader=strReader.replace("{master}","lisi");

        writer.write(strReader);
        writer.flush();
        writer.close();
        reader.close();
    }
}
